{% extends "main.html" %}
{% block content %}

<div class="layui-row">
    <div class="layui-col-md12">
      <h1 align="center">钱包列表</h1>
      
    </div>    
</div>
<div class="layui-row">
      <div class="layui-col-md10">
        &nbsp;
      </div>
      <div class="layui-col-md1">
        <button id="add_wallet_show" class="layui-btn">增加钱包</button>
      </div>
  </div>
<div class="layui-row">
    <div class="layui-col-md12">
      <table class="layui-hide" id="wallet" lay-filter="wallet_table"></table>
    </div>
    <script type="text/html" id="wallet_status">
      {% raw %}

      {{#  if(d.status == 1 ){ }}
          <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="info">已启用</a>
      {{# }else { }}
          <a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="edit">已禁用</a>
      {{# } }}

      {% endraw %}   
      <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="detail">详情</a> 
    </script>
</div>


<div id="add_wallet_show_div" style="display: none;">
        <form class="layui-form"> 
          <div class="layui-form-item">
            <label class="layui-form-label">GateIo账户</label>
            <div class="layui-input-inline">
              <select id="gateio_id" name="gateio_info" >
                {%for gateio_info in datas.gateio_info_list%}
                <option value="{{gateio_info.id}}">{{gateio_info.name}}</option>
                {%endfor%}
              </select>
            </div>
          </div>
          <div class="layui-form-item">
            <label class="layui-form-label">英文名</label>
            <div class="layui-input-inline">
              <input type="text" id="name_cn" required="" lay-verify="required"  autocomplete="off" class="layui-input">
            </div>
          </div>
          <div class="layui-form-item">
            <label class="layui-form-label">账户金额</label>
            <div class="layui-input-inline">
              <input type="text" id="amount" required="" lay-verify="required"  autocomplete="off" class="layui-input">
            </div>
          </div>


        </form>
      </div>

<script type="text/javascript">
  $(document).ready(function() {  
    

  layui.use('table', function(){
    var table = layui.table;
    
    table.render({
      elem: '#wallet'
      ,url:'/user/user_wallet_list'
      ,cellMinWidth: 80 //全局定义常规单元格的最小宽度，layui 2.2.1 新增
      ,page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
        layout: ['limit', 'count', 'prev', 'page', 'next', 'skip'] //自定义分页布局
        ,curr: 1 //设定初始在第 5 页
        ,groups: 1 //只显示 1 个连续页码
        ,first: false //不显示首页
        ,last: false //不显示尾页
        ,limit:20
        // ,theme: '#c00' 
      }
      ,cols: [[
        {field:'id', width:240, title: 'ID', sort: true}
        ,{field:'gateio', width:180, title: 'gateio', sort: true}
        ,{field:'name_cn', width:180, title: '钱包名', sort: true}
        ,{field:'amount', width:180, title: '余额', sort: true}
        ,{field:'status', width:140, title: '状态', toolbar: "#wallet_status"}
        ,{field:'ctime', title: '创建时间', sort: true}
        ,{field:'utime', title: '更新时间', sort: true}
        
      ]]
    });
    
    table.on('tool(wallet_table)', function(obj){ //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
          var data = obj.data; //获得当前行数据
          var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
          var tr = obj.tr; //获得当前行 tr 的DOM对象
         
          if(layEvent === 'detail'){ //查看
            location.href="/user/wallet_detail?oid="+data.id;
          } 
      });
  });



      $("#add_wallet_show").click(function(){
          layer.open({
              type: 1
              ,title: ['增加GateIo账户', 'font-size:18px;align:center;']
              ,closeBtn: false
              ,area: ['400px', '400px']
              ,shade: 0.8
              ,id: 'LAY_layuipro' //设定一个id，防止重复弹出
              ,btn: ['保存', '取消']
              ,btnAlign: 'c'
              ,moveType: 1 //拖拽模式，0或者1
              ,content: $('#add_wallet_show_div')
              ,success: function(layero){
                var btn = layero.find('.layui-layer-btn');
                btn.find('.layui-layer-btn0').click(function(){
                  var name_cn = $("#name_cn").val();
                  var amount = $("#amount").val();
                  var oid = $("#gateio_id").val();
                  $.ajax({
                      url: "/user/add_gateio_wallet",
                      type: "POST",
                      dataType: "json",
                      data:{"name_cn":name_cn,"amount":amount,"oid":oid},
                      success: function (result){
                          if(result['datas']['code']=="1"){
                              layer.msg(result['msg']);
                              location.href=location.href;
                          }else{
                              layer.msg(result['msg']);
                          }
                      }
                  });
                });

              }
            });
      });

    
  });
</script>
{% endblock %}